package magazzino.web.visualizzaOrdine;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;


public class PdfRicezione {

    public void print(HttpServletResponse response, String msg){
        try {
            Document document = new Document();
            document.addTitle("Dettaglio Ricezione");
            document.addAuthor("Magazzino TO01");
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);
            document.open();
            document.add(new Paragraph(msg));
            document.close();
            response.setContentType("application/pdf");
            response.setContentLength(baos.size());
            ServletOutputStream out = response.getOutputStream();
            baos.writeTo(out);
            out.flush();
        } catch (DocumentException ex) {
            Logger.getLogger(PdfRicezione.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(PdfRicezione.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}
